# 2.py 递归式

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
        temp = l1.val + l2.val
        shiwei = temp // 10
        gewei = temp % 10
        l1.val = gewei

        if shiwei != 0 and l2.next == None:
            l2.next = ListNode()
        if l1.next == None and l2.next != None:  # L1 is shorter than L2
            l1.next = ListNode()

        if shiwei != 0:
            l2.next.val += shiwei  # progress a number

        if l1.next == None and l2.next == None:
            return l1

        if l1.next != None and l2.next == None:
            l2.next = ListNode()

        self.addTwoNumbers(l1.next, l2.next)

        return l1
